#pragma strict

var fadeTexture : Texture;
var isLoading : boolean;
var fadeTime : float;
var alphaFadeValue : float;
var firstLoad : boolean;
var speed : float;
var minHeight : float;
var maxHeight : float;
var inOptions : boolean;
var minDist : float;
var maxDist : float;
var PointA : Transform;
var PointB : Transform;
var LineColor : Color32;
var LineMaterial : Material;
var worldMousePos : Ray;
var pos : Vector3;
var toPoint : Vector3;
var distance : int;

function Start(){

	alphaFadeValue = 1;
	fadeTime = 2;
	isLoading = false;
	firstLoad = true;
	speed = 150.0;
	minHeight = -10;
	maxHeight = 0;
	inOptions = false;
	minDist = -5.0;
	maxDist = 0.0;
	LineColor = Color32(110,245,255,255);
	distance = 7;

}

function Update(){
	
	var SliderOptions = GameObject.Find("opt_shadowSlider").GetComponent(ShadowDistance_Slider);
	var point = Input.mousePosition;
	point.z = distance;
	toPoint = Camera.main.ScreenToWorldPoint(point);
	
	if(inOptions){
		
		var vert : float = Input.GetAxis("Mouse ScrollWheel");
		transform.Translate(Vector3(0, vert, 0) * Time.smoothDeltaTime * speed);
		
		if(transform.position.y > maxDist){
			transform.position.y = maxDist;
		} else if(transform.position.y < minDist){
			transform.position.y = minDist;
		}
	}
					
}

function OnGUI(){
	
	if(firstLoad){
		fadeTime = 2;
		alphaFadeValue -= Mathf.Clamp01(Time.deltaTime / fadeTime);
		
		GUI.color = Color(0,0,0,alphaFadeValue);
		GUI.DrawTexture(Rect(0,0,Screen.width, Screen.height),fadeTexture);
		
		if(alphaFadeValue <= 0){
			firstLoad = false;
			fadeTime = 0;
			alphaFadeValue = 0;
		}
	}
	
	if(isLoading){
		fadeTime = 2;
		alphaFadeValue += Mathf.Clamp01(Time.deltaTime / fadeTime);
		
		GUI.color = Color(0,0,0,alphaFadeValue);
		GUI.DrawTexture(Rect(0,0,Screen.width, Screen.height),fadeTexture);
		
		if(alphaFadeValue >= 1){
			fadeTime = 0;
			alphaFadeValue = 1;
			Application.LoadLevel("Level1");
		}

	}
		
}

function OnPostRender() {

	GL.Begin( GL.LINES );
	LineMaterial.SetPass( 0 );
	GL.Color( LineColor );
	GL.Vertex3( PointA.transform.position.x, PointA.transform.position.y, PointA.transform.position.z );
	GL.Vertex3( PointB.transform.position.x, PointB.transform.position.y, PointB.transform.position.z );
	GL.End();

}
